package com.tudouji.framework.task;

import com.tudouji.project.pay.domain.SfPrebalanceRecord;
import com.tudouji.project.pay.service.ISfPrebalanceRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 自动核销
 * jsd
 */
@Slf4j
@Component("prebalanceTask")
public class PrebalanceTask {

    @Autowired
    private ISfPrebalanceRecordService prebalanceRecordService;

    public void prebalance() {
        log.debug("___________________销售订单：自动核销开始__________________");

        BatchStatus.run();

        //20231017 首先核销客户初始预收款，初始预收款核销完成后可以停掉
        prebalanceRecordService.hexiaoRecbalanceManual();

        SfPrebalanceRecord prebalanceRecord = new SfPrebalanceRecord();
        prebalanceRecord.setStats(new Integer[]{1,2});
        prebalanceRecord.setType(1);
        List<SfPrebalanceRecord> records = prebalanceRecordService.selectSfPrebalanceRecordListreverseIdisNull(prebalanceRecord);

        if (records.size() > 0) {
            for (int i = 0; i < records.size(); i++) {
                SfPrebalanceRecord record = records.get(i);

                prebalanceRecordService.hexiao(record);
            }
        }
        BatchStatus.stop();
        log.info("___________________销售订单：自动核销结束__________________");
    }

}
